/*
* Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  Implementation of LocationGestureArea. Implements pinch zoom for
*               the map view.
*/

#ifndef LOCATIONGESTUREAREA_H
#define LOCATIONGESTUREAREA_H

/*! \file
 *  \brief A custom QML component for pinch zoom.
 */

#include <QtDeclarative/QDeclarativeItem>
#include <QtDeclarative/QDeclarativeComponent>

QT_BEGIN_NAMESPACE
class QGestureEvent;
class QPanGesture;
class QPinchGesture;
class QTouchEvent;
QT_END_NAMESPACE

/*!
 *  \brief  LocationGestureArea class is a custom QML component providing
 *  pinch zoom for the map view of the application user interface.
 */
class LocationGestureArea : public QDeclarativeItem
{
    Q_OBJECT

    /*!
     * \brief Scale factor calculated from the pinch gesture.
     */
    Q_PROPERTY( qreal mapScale READ mapScale WRITE setMapScale NOTIFY mapScaleChanged )

public:

    //! Constructor.
    /*!
     *  \param parent Parent for the object.
     */
    explicit LocationGestureArea( QDeclarativeItem *parent = 0 );

    //! Destructor.
    /*!
     *  Destructor.
     */
    virtual ~LocationGestureArea();

public Q_SLOTS:

    //! Get Scale factor.
    /*!
     * \return Scale factor for the map.
     */
    qreal mapScale() const;

    //! Set Scale factor.
    /*!
     * \param scale Scale factor for the map.
     */
    void setMapScale( qreal scale );

Q_SIGNALS:

    //! Scale changed signal.
    /*!
     *  Signalled when the scale factor changes. Notifies user interface
     *  to change the zoom.
     */
    void mapScaleChanged();

    //! Multi touch started signal.
    /*!
     *  Signalled when multi touch gesture starts.
     */
    void started();

    //! Multi touch updated signal.
    /*!
     *  Signalled when multi touch gesture has changed.
     */
    void updated();

    //! Multi touch finished signal.
    /*!
     *  Signalled when multi touch gesture has finished.
     */
    void finished();

protected:

    //! Receive scene events.
    /*!
     *  Derived from QGraphicsItem. Receives events to this item.
     *  Handles the received touch events.
     *
     * \sa handleTouchEvent()
     */
    bool sceneEvent( QEvent *event );

private:

    //! Handle touch events.
    /*!
     *  Handles received touch events and calculates the zoom factor
     *  from multi touch event. Emits started(), updated() signals. When
     *  multi touch updated event is received calculates the pinch scale
     *  factor and emits mapScaleChanged() signal.
     *
     * \sa handleTouchEvent()
     */
    bool handleTouchEvent( const QTouchEvent &event );

private:
    qreal lastScaleFactor;
    qreal lastPinchFactor;
};

#endif // LOCATIONGESTUREAREA_H
